javascript

推荐列表 站点导航

当前位置:首页 > 脚本编程 > javascript >

jquery $.post方法不执行怎么办

来源:网络整理  作者:  发布时间:2020-12-22 05:42
jquery $.post方法不执行的解决方法:设置返回的数据为json数据,代码为【out.print(JSONObject.fromObject(result));】。...

本教程操作环境:windows7系统、jquery3.2.1版本,该方法适用于所有品牌电脑。

jquery $.post方法不执行的解决方法:

正确示范 :

改成: out.print(JSONObject.fromObject(result));

@RequestMapping(value = "login") public void CheckUserAccount(@RequestParam("account")String account, HttpServletResponse response) throws IOException{ JSONObject json_account = JSONObject.fromObject(account); int username = (Integer)json_account.get("username"); String password = json_account.getString("password"); logger.info("username = " + username + " password = " + password); int status; status = checkUserAccountService.IsCorrect(username, password); Map<String, Object> result = new HashMap<String, Object>(); Map<String, String> info_json = new HashMap<String, String>(); if(status == 1){ info_json.put("status", "success"); }else if(status == 0){ info_json.put("status", "errorpassword"); }else{ info_json.put("status", "noexitaccount"); } result.put("info", info_json); JSONObject json_object = JSONObject.fromObject(result); response.setContentType("text/json; charset=utf-8"); response.setHeader("Cache-Control", "no-cache"); PrintWriter out = response.getWriter(); out.print(result); out.flush(); out.close(); logger.info("验证结果是" + ((Map<String, String>)(result.get("info"))).get("status"));

重点的一句是:

jquery $.post方法不执行的解决方法:设置返回的数据为json数据,代码为【out.print(JSONObject.fromObject(result));】。

response.setContentType("text/json; charset=utf-8");

错误演示 :

jquery $.post方法不执行怎么办

关于JQuery的post回调函数不执行问题

前端的post回调函数就是不执行, 设置完断点debug还是直接跳过不执行

后台代码

此处设置返回的数据为json数据, 但是out.print(result);这里输出的是一个Map, so 前端识别不出任何数据, 结果回调函数直接跳过不执行(因为回调函数只执行json数据)

相关热词: 方法

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!

本文地址: https://v30.fanwenzhu.com/jiaob/javascript/6981.shtml

Copyright © www.juheyunku.com      关于 | 合作 | 声明 | 联系 | 更新 | 地图 | Tags

jquery $.post方法不执行怎么办

2020-12-22 编辑:

本教程操作环境:windows7系统、jquery3.2.1版本,该方法适用于所有品牌电脑。

jquery $.post方法不执行的解决方法:

正确示范 :

改成: out.print(JSONObject.fromObject(result));

@RequestMapping(value = "login") public void CheckUserAccount(@RequestParam("account")String account, HttpServletResponse response) throws IOException{ JSONObject json_account = JSONObject.fromObject(account); int username = (Integer)json_account.get("username"); String password = json_account.getString("password"); logger.info("username = " + username + " password = " + password); int status; status = checkUserAccountService.IsCorrect(username, password); Map<String, Object> result = new HashMap<String, Object>(); Map<String, String> info_json = new HashMap<String, String>(); if(status == 1){ info_json.put("status", "success"); }else if(status == 0){ info_json.put("status", "errorpassword"); }else{ info_json.put("status", "noexitaccount"); } result.put("info", info_json); JSONObject json_object = JSONObject.fromObject(result); response.setContentType("text/json; charset=utf-8"); response.setHeader("Cache-Control", "no-cache"); PrintWriter out = response.getWriter(); out.print(result); out.flush(); out.close(); logger.info("验证结果是" + ((Map<String, String>)(result.get("info"))).get("status"));

重点的一句是:

jquery $.post方法不执行的解决方法:设置返回的数据为json数据,代码为【out.print(JSONObject.fromObject(result));】。

response.setContentType("text/json; charset=utf-8");

错误演示 :

jquery $.post方法不执行怎么办

关于JQuery的post回调函数不执行问题

前端的post回调函数就是不执行, 设置完断点debug还是直接跳过不执行

后台代码

此处设置返回的数据为json数据, 但是out.print(result);这里输出的是一个Map, so 前端识别不出任何数据, 结果回调函数直接跳过不执行(因为回调函数只执行json数据)

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供学习参考!
本文地址为 https://v30.fanwenzhu.com/jiaob/javascript/6981.shtml

相关文章

风云图片

推荐阅读

返回javascript频道首页